<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>

        body{
            background: darkblue;
        }
        button{
            width: 30;
            height: 30px;
            margin: 500px 100px;
        }
    </style>
  </head>
  <body>


    <button id="btn">按钮</button>
    <script>
      function getColor() {
        var colorElements = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f";
        var colorArray = colorElements.split(",");
        var color = "#";
        for (var i = 0; i < 6; i++) {
          color += colorArray[Math.floor(Math.random() * 16)];
        }
        return color;
      }
      btn.onclick = function(){
          document.body.style.background=getColor();
      }
      
    </script>
  </body>
</html>
